$(function () {
    //1,3,6小时降水
    var colorCode = ["#A9FFFD", "#2DD4FD", "#2DA7FF", "#2D7EFF", "#51A82D", "#4AFF2D", "#FFFD2D", "#FFD12F",
        "#FFA82D", "#FF2D2D", "#CD2F30", "#AA2D2D", "#AC2DAC", "#DA2DDE", "#F02DFF"];
    var cThree = ["0.1", "2", "5", "10", "15", "25", "30", "40", "50", "60", "70", "80", "90", "100", "110"];
    var cCNTwelve = ["0.1", "2", "5", "10", "15", "25", "30", "40", "50", "60", "80", "100", "120", "140", "150"];
    var cCTwentyfour = ["0.1", "2", "5", "10", "15", "25", "35", "50", "70", "100", "120", "150", "170", "200", "230", "250"];
    //加载地图
    var map = QXMap.Map('mapContainer', {
        zoom: 8,
        center: [120.8, 28.5],
        maptype: QMAP_NORMAL_MAP
    });
    // map.addControl(new QXMap.MapTypeControl("maptypeControl", {
    //      position: "topright"
    //  }));
    map.addControl(new QXMap.LatlngControl("lnglatInfoControl", {
        position: "bottomright"
    }));

    loadSea()

    //加载海区
    function loadSea() {
        var seaArea = [
            {name: "浙江南部海区", center: {lng: 122.3, lat: 28.1}, location: "ZJSouthernSeaRegion"},
            {name: "温州沿海海区", center: {lng: 122.0, lat: 27.406}, location: "ZJWZSeaRegion"},
            {name: "浙江北部海区", center: {lng: 122.930, lat: 30.225}, location: "ZJNorthernSeaRegion"},
            {name: "浙江中部海区", center: {lng: 122.640, lat: 28.850}, location: "ZJCentralSeaRegion"}]


        for (var i = 0; i < seaArea.length; i++) {
            var option = {
                showlabel: false,
                weight: 2,
                fillOpacity: 0.2,
                fillColor: "#0033ff",
                opacity: .5,
                color: "#0033ff",
                linestyle: 'solid' //dot
            };
            QXMap.RegionLayer(seaArea[i].location, option, function (regionLayer) {
                var aa = map.addVectorLayer(regionLayer);
                //map.fitBounds(regionLayer.getBound());
            });
            var markOptions =
                {
                    showlabel: true,
                    radius: 3,
                    direction: "right",
                    color: 'transparent',
                    content: seaArea[i].name,
                    fillColor: 'red'
                }
            mark = QXMap.CircleMarker(seaArea[i].center, markOptions, function () {
                // $().unbind()
            });
            //map.addMarkerLayer(mark)
            $(mark.label._container).addClass("polyline-text");
        }
    }

    function regionclick(region) {
        // alert(region.name);
        region.setFillColor("#ff0000");
        region.setColor("#ff0000");
        region.isShow(false);
    }

    function regionover(region) {
        // alert(region.name);
        region.setFillColor("#ff0000");
        region.setColor("#ff0000");
    }

    // 二级菜单切换
    $("#nav").on("click", 'li', function () {
        if($(this).hasClass("active"))return;
        var index = $(this).index();
        var html = ''
        $(this).addClass("active").siblings(".active").removeClass("active");
        if (index === 0) {
            $("#selRain").selfShow();
            html = '<li class="active rain">逐小时降雨</li>' +
                '<li class="rain">3小时降雨</li>' +
                '<li class="rain">6小时降雨</li>' +
                '<li class="rain">12小时降雨</li>' +
                '<li class="rain">24小时降雨</li>'
            $(".tabTime ul").html(html)
            oneRain();
            changeRain()
        } else if (index === 1) {
            $("#selWind").selfShow();
            html = '<li class="active wind">3小时风力</li>'
            $(".tabTime ul").html(html)
            startWind()
        } else if (index === 2) {
            html = '<li style="width:140px" class="active rada">未来1小时雷电</li>' +
                '<li style="width:140px"  class="rada">未来1-2小时雷电</li>' +
                '<li style="width:140px" class="rada">未来3-4小时雷电</li>' +
                '<li style="width:140px"  class="rada">未来4-5小时雷电</li>' +
                '<li style="width:140px"  class="rada">未来5-6小时雷电</li>'
            $(".tabTime ul").html(html)
            getRadaData()
            $("#selVisibility").selfShow()
        }
    })

    //降雨切换
    function changeRain() {
        $(".tabTime").unbind()
        $(".tabTime").on("click", ".rain", function () {
            if($(this).hasClass("active"))return;
            $(this).addClass('active').siblings(".active").removeClass("active");
            var index = $(this).index();
            if (index == 0) {
                oneRain()
            } else if (index == 1) {
                threeRain()
            } else if (index == 2) {
                sixRain()
            } else if (index == 3) {
                twelveRain()
            } else if (index == 4) {
                twentyFourRain()
            }
        })
    }

    /*
        暴雨加载

     */

    //1小时降雨
    function oneRain() {
        var time = oneTime();
        $(".pubTime .w180").val(time);
        $(".changeTime").html(" ");
        var hour = time.slice(11, 13);
        var day = time.slice(8, 10)
        time = time.replace(/\//g, "").replace(" ", "").replace(/:/g, "") + "00";
        var productcategory = {
            title: "shengtai",
            type: "apcpsfc",
            nav: "NAFP_FOR_FTM_ST24H_ZJ",
            userid: "小时降水预报",
            num: "1",
            timetype: "H",
            year: time,
            hour: "1"
        };
        grid_controller(0.0, productcategory)
        addColorCode('1小时降水预报', colorCode, cThree);
        var ajaxUrl = 'http://10.135.30.116:8080/ZJDataCenter/api/' + productcategory.nav + '/getContourEleValidtimeListByTime'
            + '?userid=zjwlzx&pwd=123&productcategory=' + productcategory.type + '&fcstlevel=0'
            + '&time=' + time + '&timetype=' + productcategory.timetype + '&'
            + 'admincodes=330000&elements=time,hours&limitcnt=100&dataformat=json';
        $.ajax({
            url: ajaxUrl,
            type: "get",
            success: function (data) {
                if (data.DS.length > 0) {
                    $(".warningWether").addClass("hide")
                    drawAxisOne(parseInt(hour), 1, data.DS);
                    removeAxis(productcategory)
                } else {
                    $(".warningWether").removeClass("hide")
                    $(".changeTime").html('')
                }

            }
        })
    }

    oneRain()
    changeRain()

    //3小时降雨函数
    function threeRain() {
        var time = threeTime();
        $(".changeTime").html(" ")
        $(".pubTime .w180").val(time)
        var hour = time.slice(11, 13);
        var day = time.slice(8, 10)
        time = time.replace(/\//g, "");
        //time=time.replace(/:/g,"")+"00";
        var t1 = (parseInt(hour) == 20) ? '12' : "00";
        time = time.slice(0, 8) + t1 + '0000'
        var productcategory = {
            title: "OCF",
            type: "pr03",
            urls: "10.135.30.116:8080",
            nav: "NAFP_FOR_FTM_OCF_ZJ",
            userid: "3小时降水预报",
            num: "3",
            timetype: "H",
            hour: "3",
            year: time
        }
        console.log(time)
        grid_controller(0.0, productcategory)
        var ajaxUrl = 'http://10.135.30.116:8080/ZJDataCenter/api/' + productcategory.nav + '/getContourEleValidtimeListByTime'
            + '?userid=zjwlzx&pwd=123&productcategory=' + productcategory.type + '&fcstlevel=0'
            + '&time=' + time + '&timetype=' + productcategory.timetype + '&'
            + 'admincodes=330000&elements=time,hours&limitcnt=100&dataformat=json';
        addColorCode('3小时降水预报', colorCode, cThree);

        $.ajax({
            url: ajaxUrl,
            type: "get",
            success: function (data) {
                if (data.DS.length > 0) {
                    $(".warningWether").addClass("hide")
                    drawAxisThree(parseInt(hour), 3, day, 5, 2, data.DS);
                    removeAxis(productcategory)
                } else {
                    $(".warningWether").removeClass("hide")
                }

            }
        })
    }

    //threeRain()
    //6小时降雨函数
    function sixRain() {
        var time = threeTime();
        $(".changeTime").html(" ")
        $(".pubTime .w180").val(time)
        var hour = time.slice(11, 13);
        var day = time.slice(8, 10)
        time = time.replace(/\//g, "");
        // time=time.replace(/:/g,"")+"00";
        var t1 = (parseInt(hour) == 20) ? '12' : "00";
        time = time.slice(0, 8) + t1 + '0000'
        var productcategory = {
            title: "OCF",
            type: "pr06",
            urls: "10.135.30.116:8080",
            nav: "NAFP_FOR_FTM_OCF_ZJ",
            userid: "6小时降水预报",
            num: "6",
            hour: "6",
            year: time,
            timetype: "H",
        };

        grid_controller(0.0, productcategory)
        var ajaxUrl = 'http://10.135.30.116:8080/ZJDataCenter/api/' + productcategory.nav + '/getContourEleValidtimeListByTime'
            + '?userid=zjwlzx&pwd=123&productcategory=' + productcategory.type + '&fcstlevel=0'
            + '&time=' + time + '&timetype=' + productcategory.timetype + '&'
            + 'admincodes=330000&elements=time,hours&limitcnt=100&dataformat=json';
        addColorCode('6小时降水预报', colorCode, cThree);
        $.ajax({
            url: ajaxUrl,
            type: "get",
            success: function (data) {
                if (data.DS.length > 0) {
                    $(".warningWether").addClass("hide")
                    drawAxisSix(parseInt(hour), 6, day, 8, 2, data.DS);
                    removeAxis(productcategory)
                } else {
                    $(".warningWether").removeClass("hide")
                }

            }
        })
    }

    //sixRain()
    //12小时降雨函数
    function twelveRain() {
        var time = threeTime();
        $(".pubTime .w180").val(time)
        var hour = time.slice(11, 13);
        var day = time.slice(8, 10)
        time = time.replace(/\//g, "");
        // time=time.replace(/:/g,"")+"00";
        var t1 = (parseInt(hour) == 20) ? '12' : "00";
        time = time.slice(0, 8) + t1 + '0000';
        $(".changeTime").html(" ")
        var productcategory = {
            title: "OCF",
            type: "pr12",
            urls: "10.135.30.116:8080",
            nav: "NAFP_FOR_FTM_OCF_ZJ",
            userid: "12小时降水预报",
            num: "12",
            timetype: "H",
            year: time,
            hour: "12"
        };
        grid_controller(0.0, productcategory)
        addColorCode('12小时降水预报', colorCode, cCNTwelve);
        var ajaxUrl = 'http://10.135.30.116:8080/ZJDataCenter/api/' + productcategory.nav + '/getContourEleValidtimeListByTime'
            + '?userid=zjwlzx&pwd=123&productcategory=' + productcategory.type + '&fcstlevel=0'
            + '&time=' + time + '&timetype=' + productcategory.timetype + '&'
            + 'admincodes=330000&elements=time,hours&limitcnt=100&dataformat=json';
        $.ajax({
            url: ajaxUrl,
            type: "get",
            success: function (data) {
                if (data.DS.length > 0) {
                    $(".warningWether").addClass("hide")
                    drawAxisThree(parseInt(hour), 12, day, 20, 8, data.DS);
                    removeAxis(productcategory)
                } else {
                    $(".warningWether").removeClass("hide")
                }


            }
        })
    }

    //twelveRain()
    //24小时降雨函数
    function twentyFourRain() {
        var time = threeTime();
        $(".pubTime .w180").val(time)
        var hour = time.slice(11, 13);
        var day = time.slice(8, 10)
        time = time.replace(/\//g, "");
        // time=time.replace(/:/g,"")+"00";
        var t1 = (parseInt(hour) == 20) ? '12' : "00";
        time = time.slice(0, 8) + t1 + '0000'
        var productcategory = {
            title: "OCF",
            type: "pr24",
            urls: "10.135.30.116:8080",
            nav: "NAFP_FOR_FTM_OCF_ZJ",
            userid: "24小时降水预报",
            num: "24",
            timetype: "H",
            year: time,
            hour: "24"
        };
        grid_controller(0.0, productcategory)

        addColorCode('24小时降水预报', colorCode, cCTwentyfour);

        var ajaxUrl = 'http://10.135.30.116:8080/ZJDataCenter/api/' + productcategory.nav + '/getContourEleValidtimeListByTime'
            + '?userid=zjwlzx&pwd=123&productcategory=' + productcategory.type + '&fcstlevel=0'
            + '&time=' + time + '&timetype=' + productcategory.timetype + '&'
            + 'admincodes=330000&elements=time,hours&limitcnt=120&dataformat=json';
        $.ajax({
            url: ajaxUrl,
            type: "get",
            success: function (data) {
                if (data.DS.length > 0) {
                    $(".warningWether").addClass("hide")
                    drawAxistwentyFour(data.DS)
                    removeAxis(productcategory)
                } else {
                    $(".warningWether").removeClass("hide")
                }


            }
        })
    }

    //twentyFourRain()
    //获得当前时间函数
    function getTime() {
        var date = new Date();
        var Day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
        var Year = date.getFullYear();
        var Mouth = date.getMonth() >= 9 ? date.getMonth() + 1 : "0" + (date.getMonth() + 1);
        var hour = date.getHours() > 9 ? date.getHours() : "0" + date.getHours();
        var min = date.getMinutes() > 9 ? date.getMinutes() : "0" + date.getMinutes();
        var end = Year + "/" + Mouth + "/" + Day + " " + hour + ":" + "00";
        return end;
    };

    //3小时降雨发布函数
    function threeTime() {
        //var nowTime=getTime();
        //var hour=nowTime.slice(11,13);
        var date = new Date();
        var hour = date.getHours();
        var min=date.getMinutes();
        // if(parseInt(min)<30)hour=parseInt(hour)-1;
        // console.log(hour,min)
        if (parseInt(hour) < 10) {
            date.setDate(date.getDate() - 1);
            hour = "08";
        } else if (parseInt(hour) >= 10 && parseInt(hour) < 15) {
            date.setDate(date.getDate() - 1);
            hour = "20";
        } else {
            hour = "08";
        }
        var day = date.getDate()
        day = day > 9 ? day : "0" + day;
        var month = (date.getMonth() + 1)
        month = month > 9 ? month : "0" + month;
        return date.getFullYear() + "/" + month + "/" + day + "/" + hour + ":00";
    }

    // 增加色标
    function addColorCode(title, colorCode, cc) {
        var html = ' <p>' + title + '</p><ul>'
        for (var i = 0; i < colorCode.length; i++) {
            html += '<li>' +
                '<span  style="background:' + colorCode[i] + '"></span>' +
                '<span>' + cc[i] + '</span>' +
                '</li>'
        }
        html += "</ul>"
        $(".colorCode").html(html)
    }

    //时间切换函数
    function removeAxis(productcategory) {
        var index = 0;
        $(".changeTime").unbind();
        $(".changeTime").on("click", "button", function (e) {
            e.preventDefault();
            var len = $(".changeTime ul li")
            if ($(this).hasClass("changeNext")) {
                $(this).siblings("button").prop("disabled", false)
                len.eq(index).addClass("hide").removeClass("show")
                len.eq(++index).addClass("active").siblings(".active").removeClass("active")
                var year = len.eq(index).attr('year');
                var hour = len.eq(index).attr("hour");
                productcategory.year = year
                productcategory.hour = hour

                grid_controller(0, productcategory)
                if (len.length - index <= 8) {
                    $(this).prop("disabled", true)
                }
            } else {
                --index
                $(this).siblings("button").prop("disabled", false)
                len.eq(index)
                len.eq(index).removeClass("hide").addClass("show").addClass("active").siblings(".active").removeClass("active")
                var year = len.eq(index).attr('year');
                var hour = len.eq(index).attr("hour");
                productcategory.year = year
                productcategory.hour = hour
                grid_controller(0, productcategory)
                if (index == 0) {
                    $(this).prop("disabled", true);
                }
            }
        })
        $(".changeTime").on("mouseenter", "li", function () {
            $(this).addClass("active").siblings(".active").removeClass("active");
            var year = $(this).attr('year');
            var hour = $(this).attr("hour");
            productcategory.year = year
            productcategory.hour = hour
            grid_controller(0, productcategory)
        })
        $(".changeTime").on("mouseleave", "li", function () {
            // $(this).removeClass("active");
        })
    }

    //绘制1小时底部时间轴
    function drawAxisOne(initTime, step, data) {
        var html = '<button class="changeNext lf"><</button><ul>'
        var j = 1;
        var date = new Date();
        for (var i = 0; i < data.length; i++) {
            var time = initTime + j * step;
            j++
            html += '<li class="' + (i == 0 ? 'active' : "") + '" hour="' + data[i].hours + '" year="' + data[i].time + '">' +
                '<span class="upRect"></span>' +
                '<span>' + (time > 23 ? 0 : time) + ':00</span>'
            if (time > 23) {
                initTime = 1;
                j = 0;
                date.setDate(date.getDate() + 1)
                html += '<i ></i>' +
                    '<b class="changeDay">' + (date.getMonth() + 1) + '/' + date.getDate() + '</b>'
            }
            html += '</li>'
        }
        html += '</ul><button class="changePrev rt" disabled>></button> '
        $(".changeTime").html(html)
    }

    //绘制3小时底部时间轴
    function drawAxisThree(initTime, step, day, endT, num, data) {
        var html = '<button class="changeNext lf"><</button><ul>';
        var j = 1;
        var time
        var date = new Date();
        date.setDate(day);
        for (var i = 0; i < data.length; i++) {
            time = initTime + j * step;

            j++
            html += '<li class="' + (i == 0 ? 'active' : "") + '" hour="' + data[i].hours + '" year="' + data[i].time + '">' +
                '<span class="upRect"></span>' +
                '<span>' + (time > 23 ? num : time) + ':00</span>'
            if (time > 23) {
                initTime = endT;
                j = 0;
                date.setDate(date.getDate() + 1)
                html += '<i ></i>' +
                    '<b class="changeDay">' + (date.getMonth() + 1) + '/' + date.getDate() + '</b>'
            }
            html += '</li>'
        }
        html += '</ul><button class="changePrev rt" disabled>></button> '
        $(".changeTime").html(html)
    }

    function drawAxisSix(initTime, step, day, endT, num, data) {
        var html = '<button class="changeNext lf"><</button><ul>';
        var j = 1;
        var time
        var date = new Date();
        date.setDate(day);
        for (var i = 0; i < data.length; i++) {
            time = initTime + j * step;
            if (data[i].hours % 6 == 0) {
                j++
                html += '<li class="' + (i == 0 ? 'active' : "") + '" hour="' + data[i].hours + '" year="' + data[i].time + '">' +
                    '<span class="upRect"></span>' +
                    '<span>' + (time > 23 ? num : time) + ':00</span>'
                if (time > 23) {
                    initTime = endT;
                    j = 0;
                    date.setDate(date.getDate() + 1)
                    html += '<i ></i>' +
                        '<b class="changeDay">' + (date.getMonth() + 1) + '/' + date.getDate() + '</b>'
                }
                html += '</li>'
            }

        }
        html += '</ul><button class="changePrev rt" disabled>></button> '
        $(".changeTime").html(html)
    }

    //绘制24小时底部时间轴
    function drawAxistwentyFour(data) {
        var date = new Date();
        var html = '<button class="changeNext lf"><</button><ul>';
        for (var i = 0,j=0; i < data.length; i++) {
            if (data[i].hours % 24 == 0) {
                date.setDate(date.getDate() + j)
                html += '<li class="' + (i == 0 ? 'active' : "") + '" hour="' + data[i].hours + '" year="' + data[i].time + '">' +
                    '<span class="upRect"></span>' +
                    '<span>' + date.getDate() + '日</span>'
                if (date.getDate() == 1) {
                    html += '<i ></i>' +
                        '<b class="changeDay">' + (date.getMonth() + 1) + '月</b>'
                }
                html += '</li>'
                j=1
            }
        }
        html += '</ul><button class="changePrev rt" disabled>></button> '
        $(".changeTime").html(html)
    }

    //获得1小时降雨时间
    function oneTime() {
        var date = new Date();
        var day = date.getDate();
        var month = date.getMonth() + 1;
        // date.setDate(date.getDate()-1)
        date.setHours(date.getHours() - 1)
        var hour = date.getHours();

        hour = hour > 9 ? hour : '0' + hour;
        month = month > 9 ? month : '0' + month;
        day = day > 9 ? day : '0' + day;
        return date.getFullYear() + '/' + month + '/' + day + ' ' + hour + ":00"
    }

    //加载暴雨控件
    function grid_controller(x, productcategory) {
        QXMap.removeGridMapProduct();
        QXMap.removeVectorMapProduct();
        x = parseFloat(x).toFixed(1);
        var mapProductOptions = {
            productcategory: productcategory.type,
            time: productcategory.year,
            regioncode: '330000',
            method: productcategory.nav,
            interface: 'getContourEleByTimeAndRegionCode',
            key: 'zjwlzx',
            pwd: '123',
            level: 0,
            validtime: productcategory.hour,
            gridmethod: productcategory.nav,
            gridinterface: 'getGridForecastEleGridInRectByTimeAndLevelAndValidtime',
            nlat: 55,
            slat: 18,
            wlon: 116,
            elon: 132,
            isshowzero: false,
            isshowcontrol: true,
            position: "topleft",
            isforecast: true
        };
        var product = QXMap.addVectorMapProduct(mapProductOptions, function (data) {
            if (data == null) return;
            QXMap.showValueClassByType(x);
        });
        map.setZoom(8);
        map.setCenter({lng: 120.8, lat: 28.5})

    };

    //风启动函数
    function startWind() {
        // wind(3);
        // drawWindAxis(15,3);
        getData()
    }

    //startWind()
    //风力控件
    function wind(time, num) {
        QXMap.removeGridMapProduct();
        QXMap.removeVectorMapProduct();
        console.log(1)
        var mapProductOptions = {
            productcategory: 'windv',
            productcategory_U: 'windd',
            productcategory_V: 'windv',
            time: time,
            regioncode: '330000',
            method: 'NAFP_FOR_FTM_OCF_ZJ',
            interface: 'getContourEleByTimeAndRegionCode',
            key: 'zjwlzx',
            pwd: '123',
            level: 0,
            validtime:num,
            gridmethod: 'NAFP_FOR_FTM_OCF_ZJ',
            gridinterface: 'getGridForecastEleGridInRectByTimeAndLevelAndValidtime',
            nlat: 55,
            slat: 18,
            wlon: 110,
            elon: 135,
            iswind: true,
            isshowzero: true,
            isshowcontrol: true,
            position: "topright",
            isforecast: true,
            isshowgridselect: true
        }

        var product = QXMap.addVectorMapProduct(mapProductOptions, function (data) {
            var da = data._data;
            var r = [];
            for (var i = 0; i < da.length; i++) {
                for (var j = i + 1; j < da.length; j++)
                    if (da[i].color === da[j].color) j = ++i;
                r.push(da[i]);
            }
            addWindColorCode("风力速度", r, " m/s")

            if (data == null) return;
        });
    }

    //大风数据返回函数
    function getData() {
        var time = getWindTime();
        $(".pubTime input").val(time)
        time = time.replace(/\//g, "");
        time = time.replace(" ", "")
        time = time.replace(/:/g, "") + "00"

        var day = time.slice(6, 8)
        console.log(time)
        var ajaxUrl = 'http://10.135.30.116:8080/ZJDataCenter/api/NAFP_FOR_FTM_OCF_ZJ/getContourEleValidtimeListByTime?userid=aa&pwd=123&productcategory=pr03&fcstlevel=0&time=' + time + '&timetype=D&admincodes=330000&elements=time,hours&limitcnt=100&dataformat=json'
        $.ajax({
            url: ajaxUrl,
            type: "get",
            success: function (data) {
                console.log(data)
                if (data.returnCode == 0) {
                    $(".warningWether").addClass("hide")
                    var arr = []
                    for (var i = 0, hour, list = data.DS; i < list.length; i++) {
                        hour = list[i].time.slice(8, 10);
                        if (hour == 12) {
                            arr.push(list[i])
                        } else {
                            arr.push(list[i])
                        }
                    }
                    wind(arr[0].time, arr[0].hour)
                    if (arr[0].time.slice(8, 10) == 12) drawAxisThree(12, 3, day, 3, 0, arr)
                    else drawAxisThree(0, 3, day, 3, 0, arr)

                    removeWindAxis();
                } else {
                    $(".warningWether").removeClass("hide")
                }
            }
        })
    }

    //大风获得获得时间
    function getWindTime() {
        var date = new Date();
        var hour = date.getHours()
        if (hour < 18) {
            date.setDate(date.getDate() - 1)
            hour = 12
        } else {
            hour = '00'
        }
        var Day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
        var Year = date.getFullYear();
        var Mouth = date.getMonth() >= 9 ? date.getMonth() + 1 : "0" + (date.getMonth() + 1);
        var end = Year + "/" + Mouth + "/" + Day + " " + hour + ":" + "00";
        return end;
    };

    //大风色标生成
    function addWindColorCode(title, colorCode, U) {
        var html = ' <p>' + title + '</p><ul>'
        if (colorCode.join("")) {
            for (var i = 0; i < colorCode.length; i++) {
                var r = colorCode[i].color.lastIndexOf(",")

                html += '<li style="width:65px">' +
                    '<span  style="background: rgb(' + colorCode[i].color.slice(0, r) + ')"></span>' +
                    '<span>' + colorCode[i].value + U + '</span>' +
                    '</li>'
            }
            html += "</ul>"
            $(".colorCode").html(html)
        }
    }

    //大风底部时间切换函数
    function removeWindAxis() {
        var index = 0;
        $(".changeTime").unbind();
        $(".changeTime").on("click", "button", function (e) {
            e.preventDefault();
            var len = $(".changeTime ul li")
            if ($(this).hasClass("changeNext")) {
                $(this).siblings("button").prop("disabled", false)
                $(".changeTime ul li").eq(index).addClass("hide").removeClass("show")
                $(".changeTime ul li").eq(++index).addClass("active").siblings(".active").removeClass("active")
                if (len.length - index <= 8) {
                    $(this).prop("disabled", true)
                }
                var year = len.eq(index).attr('year');
                var hour = len.eq(index).attr("hour");
                wind(year, hour)
            } else {
                --index
                $(this).siblings("button").prop("disabled", false)
                $(".changeTime ul li").eq(index)
                $(".changeTime ul li").eq(index).removeClass("hide").addClass("show").addClass("active").siblings(".active").removeClass("active")
                if (index == 0) {
                    $(this).prop("disabled", true);
                }
                var year = len.eq(index).attr('year');
                var hour = len.eq(index).attr("hour");
                wind(year, hour)
            }
        })
        $(".changeTime").on("mouseenter", "li", function () {
            $(this).addClass("active").siblings(".active").removeClass("active");
            var len = $(".changeTime ul li")
            var year = $(this).attr('year');
            var hour = $(this).attr("hour");
            wind(year, hour)
        })
        $(".changeTime").on("mouseleave", "li", function () {
            // $(this).removeClass("active");
        })
    }

    //雷电获得数据
    function getRadaData() {
        var time = getRadaTime();
        $(".pubTime input").val(time)
        time = time.replace(/\//g, "");
        time = time.replace(" ", "")
        time = time.replace(/:/g, "") + "00";

        var ajaxUrl = 'http://10.135.30.116:8080/ZJDataCenter/api/RADA_L3_MST_Lightning/getContourValidtimeListByTime?userid=aa&pwd=123&productcategory=lightning&fcstlevel=0&time=' + time + '&timetype=D&admincodes=330000&elements=time,hours&limitcnt=120&dataformat=json'

        $.ajax({
            url: ajaxUrl,
            type: "get",
            success: function (data) {
                var colornum = [
                    {color: '0,255,255,255', value: 0},
                    {color: '255,0,0,255', value: 1},
                    {color: '255,255,255,0', value: 10},
                    {color: '255,255,185,15', value: 100},
                    {color: '255,255,0,0', value: 1000}]
                if (data.returnCode == 0) {
                    var arr = data.DS.slice(0, 6);
                    drawAxisMin(data.DS, 0)
                    addWindColorCode("雷电", colornum, " 次");
                    radaEnter();
                    $(".tabTime").unbind()
                    $(".tabTime").on("click", ".rada", function () {
                        $(this).addClass('active').siblings(".active").removeClass("active");
                        var index = $(this).index();
                        if (index == 0) {
                            drawAxisMin(data.DS, index)
                        } else if (index == 1) {
                            drawAxisMin(data.DS, index)
                        } else if (index == 2) {
                            drawAxisMin(data.DS, index)
                        } else if (index == 3) {
                            drawAxisMin(data.DS, index)
                        } else if (index == 4) {
                            drawAxisMin(data.DS, index)
                        }
                    })

                }
            }
        })
    }

    //雷电控件
    function rada(time, hour) {
        QXMap.removeGridMapProduct();
        QXMap.removeVectorMapProduct();
        var mapProductOptions = {
            productcategory: 'lightning',
            time: time,
            regioncode: '330000',
            method: 'RADA_L3_MST_Lightning',
            interface: 'getContourByTimeAndRegionCode',
            key: 'zjwlzx',
            pwd: '123',
            level: 0,
            validtime: hour,
            gridmethod: 'RADA_L3_MST_Lightning',
            gridinterface: 'getRadarGridInRectByTimeAndLevelAndValidtime',
            nlat: 55,
            slat: 18,
            wlon: 116,
            elon: 125,
            isshowzero: false,
            isshowcontrol: true,
            position: "topright",
            isforecast: true,
            isshowgridselect: false
        }
        var product = QXMap.addVectorMapProduct(mapProductOptions, function (data) {
            if (data == null) return;
            // QXMap.showValueClassByType(31.0);
        })

    }

    //绘制10分钟时间图
    function drawAxisMin(data, index) {
        var arr = data.slice(index * 6, index * 6 + 6);

        var html = "<ul>";
        for (var i = 0; i < arr.length; i++) {
            html += '<li class="' + (i == 0 ? 'active' : "") + '" hour="' + arr[i].hours + '" year="' + arr[i].time + '">' +
                '<span class="upRect"></span>' +
                '<span>' + (i + 1) * 10 + '分钟</span>'
            html += '</li>'
        }
        html += "</ul>"
        $(".changeTime").html(html);
        rada(arr[0].time, arr[0].hours)
    }

    //鼠标移入雷电的事件
    function radaEnter() {
        $(".changeTime").unbind()
        $(".changeTime").on("mouseenter", "li", function () {
            $(this).addClass("active").siblings(".active").removeClass("active");
            var time = $(this).attr('year');
            var hour = $(this).attr("hour");
            rada(time, hour)

        })
    }

    //获得当前整点整分时间
    function getRadaTime() {
        var date = new Date();
        var day = date.getDate()
        var hour = date.getHours();
        var month = (date.getMonth() + 1);
        hour = hour > 9 ? hour : '0' + hour
        month = month > 9 ? month : '0' + month
        day = day > 9 ? day : '0' + day;
        var min = date.getMinutes() + "";
        min = min[0] + "0";
        return date.getFullYear() + "/" + month + "/" + day + " " +
            hour + ":" + min;
    }


    jQuery.fn.selfShow = function () {
        this.removeClass("hide").addClass("show").siblings(".show").removeClass("show").addClass("hide")
    }

})